package org.veridiandynamics.server.domain;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Map;

/**
 * This represents the Admin domain object. Stores information about the Admin.
 *
 */
public class Admin extends User implements Serializable
{

	private static final long serialVersionUID = 20L;
	
	/**
	 * Constructor for an Admin with available information.
	 * 
	 * @param personalInfo Map containing information to be stored about admin.
	 */
	public Admin(Map<String, String> personalInfo)
	{
		myRoles = new HashSet<Roles>();
		myRoles.add(new Roles(RoleLookup.Role.ADMIN));
		setFirstName(personalInfo.get("first name"));
		setLastName(personalInfo.get("last name"));
		setMiddleName(personalInfo.get("middle name"));
		setStreetAddress(personalInfo.get("address"));
		setCity(personalInfo.get("city"));
		setState(personalInfo.get("state"));
		setZip(Integer.parseInt(personalInfo.get("zip")));
		setTelephone(personalInfo.get("telephone"));
		setCell(personalInfo.get("cell"));
		setEmail(personalInfo.get("email"));
		setUsername(personalInfo.get("username"));
		setPassword(personalInfo.get("password"));
	}
	
	/**
	 * Default constructor.
	 */
	public Admin()
	{
		
	}
	
	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	public String toString()
	{
		String retVal = "";
		retVal += getName() + "\n";
		return retVal;
	}
	

	
	/**
	 * Writes object to store it.
	 * 
	 * @param outputStream
	 * @throws IOException
	 */
	private void writeObject(ObjectOutputStream outputStream) throws IOException {
		outputStream.defaultWriteObject();
	}
	
	/**
	 * Attempts to read object.
	 * 
	 * @param inputStream 
	 * @throws ClassNotFoundException If object cannot be found
	 * @throws IOException
	 */
	private void readObject(ObjectInputStream inputStream) throws ClassNotFoundException, IOException {
		inputStream.defaultReadObject();
	}
}
